"use strict";
cc._RF.push(module, 'e74172bE7xNIar42zhPq36E', 'o1DialogBox');
// scripts/engines/modules/uiModule/o1DialogBox.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../gameEngine");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var o1DialogBox = /** @class */ (function (_super) {
    __extends(o1DialogBox, _super);
    function o1DialogBox() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.showNode = null;
        _this.ndBg = null;
        _this.lbTitle = null;
        _this.lbMessage = null;
        _this.lbOk = null;
        _this.lbCancel = null;
        _this.lbVideoCount = null;
        _this.lookVideoNode = null;
        _this.btCancel = null;
        _this.m_videoCountInfo = null;
        _this.m_callBack = null;
        _this.m_lookVideoSource = null;
        _this.m_thisClickTween = null;
        _this.m_runIng = false;
        return _this;
        // update (dt) {}
    }
    o1DialogBox.prototype.onLoad = function () {
        var O1HD = window['O1HD'];
        O1HD.getModules().uiControlModule.setGaussianMode(this.ndBg);
    };
    o1DialogBox.prototype.start = function () {
    };
    o1DialogBox.prototype.showAction = function () {
        gameEngine_1.modules().uiControlModule.showHideDialogAnimation(this.showNode, true);
        //
    };
    o1DialogBox.prototype.hideAction = function () {
        var _this = this;
        gameEngine_1.modules().uiControlModule.showHideDialogAnimation(this.showNode, false, function () {
            _this.node.destroy();
        });
        //
    };
    o1DialogBox.prototype.showDialogBox = function (title, message, isCancelOk, clickCallBack, okButtonText, cancelButtonText, lookVideoCount, lookVideoSource) {
        if (okButtonText === void 0) { okButtonText = '确定'; }
        if (cancelButtonText === void 0) { cancelButtonText = '取消'; }
        if (lookVideoCount === void 0) { lookVideoCount = 0; }
        this.m_lookVideoSource = lookVideoSource || '未传递目的';
        this.lbTitle.string = title;
        this.lbMessage.string = message;
        // this.btCancel.active = isCancelOk;
        this.m_callBack = clickCallBack;
        //要看视频次数
        if (lookVideoCount > 0) {
            this.m_videoCountInfo = {
                currLookCount: 0,
                setLookCount: lookVideoCount,
            };
        }
        else {
            this.m_videoCountInfo = null;
        }
        // this.lbOk.string = okButtonText;
        // this.lbCancel.string = cancelButtonText;
        this.onUpdateLookVideoCount();
        this.showAction();
    };
    o1DialogBox.prototype.onBtnOkCancel = function (event, custom) {
        var _this = this;
        if (this.m_videoCountInfo) {
            if (custom == 'ok') {
                //
                var O1HD_1 = window['O1HD'];
                //
                if (O1HD_1 == null) {
                    console.error('#95错误 框架引擎未初始化 || 未添加到全局变量', O1HD_1);
                    return;
                }
                cc.game.pause();
                O1HD_1.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                    cc.game.resume();
                    _this.m_videoCountInfo.currLookCount++;
                }, function (e) {
                    cc.game.resume();
                    O1HD_1.getModules().uiControlModule.showMessageBox('视频观看失败');
                    console.info("快手视频加载失败");
                }, function () {
                    cc.game.resume();
                    _this.onUpdateLookVideoCount();
                    //
                    if (_this.m_videoCountInfo.currLookCount >= _this.m_videoCountInfo.setLookCount) {
                        _this.m_callBack && _this.m_callBack(true);
                        _this.hideAction();
                    }
                }, this.m_lookVideoSource);
            }
            else {
                this.m_callBack && this.m_callBack(false);
                this.hideAction();
            }
        }
        else {
            this.m_callBack && this.m_callBack(custom == 'ok');
            this.hideAction();
        }
    };
    o1DialogBox.prototype.onBtnThis = function () {
        var _this = this;
        var width = 8;
        //
        if (this.m_thisClickTween == null) {
            var once = cc.tween(this.showNode)
                .call(function () {
                _this.m_runIng = true;
            })
                .by(0.02, { x: width, y: width })
                .by(0.02, { x: 0, y: -width })
                .by(0.02, { x: -width, y: -width })
                .by(0.02, { x: -width, y: 0 })
                .by(0.02, { x: 0, y: width })
                .by(0.02, { x: width, y: 0 });
            //
            this.m_thisClickTween = cc.tween(this.showNode)
                .then(once)
                .repeat(3)
                .call(function () {
                _this.m_runIng = false;
            });
        }
        //
        if (this.m_runIng) {
            return;
        }
        this.m_thisClickTween.start();
    };
    o1DialogBox.prototype.onUpdateLookVideoCount = function () {
        if (this.m_videoCountInfo) {
            // this.lookVideoNode.active = true;
            var _a = this.m_videoCountInfo, setLookCount = _a.setLookCount, currLookCount = _a.currLookCount;
            this.lbVideoCount.string = setLookCount > 1 ? "(" + currLookCount + "/" + setLookCount + ")" : '';
        }
        else {
            // this.lookVideoNode.active = false;
            this.lbVideoCount.string = '';
        }
    };
    __decorate([
        property(cc.Node)
    ], o1DialogBox.prototype, "showNode", void 0);
    __decorate([
        property(cc.Node)
    ], o1DialogBox.prototype, "ndBg", void 0);
    __decorate([
        property(cc.Label)
    ], o1DialogBox.prototype, "lbTitle", void 0);
    __decorate([
        property(cc.Label)
    ], o1DialogBox.prototype, "lbMessage", void 0);
    __decorate([
        property(cc.Label)
    ], o1DialogBox.prototype, "lbOk", void 0);
    __decorate([
        property(cc.Label)
    ], o1DialogBox.prototype, "lbCancel", void 0);
    __decorate([
        property(cc.Label)
    ], o1DialogBox.prototype, "lbVideoCount", void 0);
    __decorate([
        property(cc.Node)
    ], o1DialogBox.prototype, "lookVideoNode", void 0);
    __decorate([
        property(cc.Node)
    ], o1DialogBox.prototype, "btCancel", void 0);
    o1DialogBox = __decorate([
        ccclass
    ], o1DialogBox);
    return o1DialogBox;
}(cc.Component));
exports.default = o1DialogBox;

cc._RF.pop();